package com.app.micaihu.view.main.view.keybord;

import android.app.Activity;
import android.util.Log;
import android.util.TypedValue;

/**
 * Copyright (C) 2016,深圳市红鸟网络科技股份有限公司 All rights reserved.
 * 项目名称：
 * 类的描述：
 * 创建人员：Robi
 * 创建时间：2016/12/22 17:20
 * 修改人员：Robi
 * 修改时间：2016/12/22 17:20
 * 修改备注：
 * Version: 1.0.0
 */
public class Control {
    RSoftInputLayout2 mSoftInputLayout;
    Activity mActivity;

    public Control(RSoftInputLayout2 softInputLayout, Activity activity) {
        mSoftInputLayout = softInputLayout;
        mActivity = activity;
    }

    public void initContentLayout() {
        mSoftInputLayout.addOnEmojiLayoutChangeListener(new RSoftInputLayout2.OnEmojiLayoutChangeListener() {
            @Override
            public void onEmojiLayoutChange(boolean isEmojiShow, boolean isKeyboardShow, int height) {

                Log.w("Robi", "表情显示:" + mSoftInputLayout.isEmojiLayoutShow() + " 键盘显示:" + mSoftInputLayout.isSoftKeyboardShow()
                        + " 表情高度:" + height + " 键盘高度:" + height);
                String log = "表情显示:" + isEmojiShow + " 键盘显示:" + isKeyboardShow + " 高度:" + height;
                Log.e("Robi", log);
            }
        });
    }


    public boolean onBackPressed() {
        return mSoftInputLayout.requestBackPressed();
    }

    public boolean isEmojiLayoutShow() {
        return mSoftInputLayout.isEmojiLayoutShow();
    }
    public boolean isSoftKeyboardShow() {
        return  mSoftInputLayout.isSoftKeyboardShow();
    }
    public void onSetPadding100Click() {
        mSoftInputLayout.showEmojiLayout(dpToPx(100));
    }

    public void onSetPadding400Click() {
        mSoftInputLayout.showEmojiLayout(dpToPx(400));
    }

    public void onShowClick() {
        mSoftInputLayout.showEmojiLayout();
    }

    public void onHideClick() {
        mSoftInputLayout.hideEmojiLayout();
    }

    private int dpToPx(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, mActivity.getResources().getDisplayMetrics());
    }

    public void onLayoutFullScreen() {
        mSoftInputLayout.requestLayout();
        mSoftInputLayout.post(new Runnable() {
            @Override
            public void run() {
                mSoftInputLayout.requestLayout();
            }
        });
    }
}
